from PyQt4.QtGui import QWidget, QLabel, QPixmap, QFont

class SlideGauge(QWidget):
	def __init__(self, *args, **kw):
		QWidget.__init__(self, *args, **kw)

		pic = QLabel(self)
		pic.setPixmap(QPixmap("work/slide_gauge.png"))
		pic.setGeometry(2, 0, 53,158)

		ptr = QLabel(self)
		ptr.setPixmap(QPixmap("work/gauge_pointer.png"))
		ptr.setGeometry(0, 22, 22,15)

		self.pointer = ptr
		self.base_y = 22
		self.target_y = 22
		self.current_y = 22

	def choose(self, n):
		self.target_y = self.base_y + n * 21
		print "n = ", n
		print "current = ", self.current_y
		print "target = ", self.target_y
		#self.pointer.move(0, self.pointer.target_y)

		self.timer = QtCore.QTimer(self);
		self.timer.timeout.connect(self.move_pointer)
		self.timer.start(20);

	def move_pointer(self):
		if self.target_y == self.current_y:
			self.pointer.move(0, self.target_y)
			self.timer.stop()
			self.timer = None
			return

		diff = self.current_y - self.target_y
		if diff > 0:
			self.current_y -= 1
		else:
			self.current_y += 1
		self.pointer.move(0, self.current_y)
			
			

